<?php
/**
 * Created by PhpStorm.
 * User: liuchaozhong
 * Date: 2018/9/1
 * Time: 上午9:20
 */
namespace App\Admin\Extensions\Tools;

use Encore\Admin\Grid\Tools\BatchAction;

class CheckPost extends BatchAction
{
    protected $action;

    public function __construct($action = 1)
    {
        $this->action = $action;
    }

    public function script()
    {
        return <<<JS
        $('{$this->getElementClass()}').on('click', function() {
            $.ajax({
                method: 'post',
                url: '{$this->resource}/checkPost',
                data: {
                    _token:LA.token,
                    ids: selectedRows(),
                    action: {$this->action}
                },
                success: function (ret) {
                     toastr.success(ret.msg);
                     $.pjax.reload('#pjax-container');
                }
            });
        });
JS;
    }

}